#!/bin/bash

cmd="gmx_mpi mdrun -ntomp 7 -nb gpu -pme cpu -v --deffnm md -cpi md.cpt -g test.log"

lrank=$OMPI_COMM_WORLD_LOCAL_RANK
echo "lrank ${lrank}"

case ${lrank} in
[0])
export HIP_VISIBLE_DEVICES=0
export UCX_NET_DEVICES=mlx5_0:1
export UCX_IB_PCI_BW=mlx5_0:50Gbs
export GOMP_CPU_AFFINITY='0-6'
numactl --cpunodebind=0 --membind=0 ${cmd}
;;
[1])
export HIP_VISIBLE_DEVICES=1
export UCX_NET_DEVICES=mlx5_1:1
export UCX_IB_PCI_BW=mlx5_1:50Gbs
export GOMP_CPU_AFFINITY='8-14'
numactl --cpunodebind=1 --membind=1 ${cmd}
;;
[2])
export HIP_VISIBLE_DEVICES=2
export UCX_NET_DEVICES=mlx5_2:1
export UCX_IB_PCI_BW=mlx5_2:50Gbs
export GOMP_CPU_AFFINITY='16-22'
numactl --cpunodebind=2 --membind=2 ${cmd}
;;
[3])
export HIP_VISIBLE_DEVICES=3
export UCX_NET_DEVICES=mlx5_3:1
export UCX_IB_PCI_BW=mlx5_3:50Gbs
export GOMP_CPU_AFFINITY='24-30'
numactl --cpunodebind=3 --membind=3 ${cmd}
;;
esac
